<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var body = document.body;
        body.innerHTML = '<div><img src="img/xiaoxing.jpg"/><button>删除</button></div>';
        var imgs = document.querySelector('img');
        var btn = document.querySelector('button');
        btn.style.width = 50 + 'px';
        btn.style.height = 30 + 'px';
        btn.onclick = function() {
            if (imgs.scr != '') {
                // imgs.src = 'img/xiaoxing.jpg';
                imgs.src = '';
            }
            // } else {
            //     // imgs.src = 'img/xiaoxing.jpg';
            //     imgs.src = '';
            //     imags.alt = '';
            // }
        }
    </script>
</body>
</html>